package com.ktmall.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * 分页查询订单列表时，用此类接收从小程序传递过来的请求参数。
 * @version v1.0
 * @Author 郴州科泰
 * @Create 2024-08-11 - 23:29
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderParam<T> {

    private Integer orderState; // 订单状态
    private Integer userId;  // 登录用户的id
    protected Integer currPageNo;  // 当前页码
    protected Integer pageSize;  // 每页显示的数据行数
    protected Integer totalCount;  //总的记录数
    protected Integer totalPageCount; //总的页数
    protected List<T> list;   // 分页列表数据

    public void setCurrPageNo(Integer currPageNo) {
        //对传递的页码进行边界判断
        if (currPageNo < 1) {
            currPageNo = 1;
        }
        if (this.totalPageCount > 0 && currPageNo > this.totalPageCount) {
            currPageNo = this.totalPageCount;
        }
        this.currPageNo = currPageNo;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        // 计算总的页数
        this.totalPageCount = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
    }
}
